# -*- coding: utf-8 -*-
from flask_sqlalchemy import SQLAlchemy
from config import config, ProjectConfig
from flask import Flask
from flask_login import LoginManager
from celery import Celery
from flask_cache import Cache



from flask_login import current_user
from flask_principal import identity_loaded,UserNeed,RoleNeed

#用户认证
login_manager=LoginManager()
#认证加密程度
login_manager.session_protection='strong'
#登录认证的处理视图
login_manager.login_view='account_bp.big_data_login'
#登录提示信息
login_manager.login_message=u'对不起，请先登录'

db = SQLAlchemy()
celery = Celery(__name__, broker=ProjectConfig.CELERY_BROKER_URL)
cache = Cache()
#celery.conf.CELERY_TIMEZONE = 'Asia/Shanghai'  #设置时区为中国时区



def create_app(config_name):
    app = Flask (__name__)
    login_manager.init_app(app)
    app.config.from_object(config[config_name])
    db.init_app(app)
    #cache.init_app (app)


    from apps.account.views import account_bp
    app.register_blueprint(account_bp)

    from apps.setting.views import settings
    app.register_blueprint (settings)




    return app






